package org.ragdollcat.secondaiagent.agent;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.io.IOException;

@EqualsAndHashCode(callSuper = true)
@Data
@Slf4j
public abstract class ReActAgent extends BaseAgent{

    /**
     * 定义每次循环中执行的步骤，子类实现
     *
     * @return
     */
    @Override
    public String step(SseEmitter sseEmitter) {
        try {
            if (!think(sseEmitter)){
                return "Thinking complete - no action needed";
            }
            return act();
        } catch (Exception e) {
            log.error("步骤执行失败，原因:",e);
            return "步骤执行失败：" + e.getMessage();
        }

    }


    /**
     * 思考 判断是否需要调用工具
     * @return
     */
    public abstract boolean think(SseEmitter sseEmitter) throws IOException;


    /**
     * 行动 调用工具
     * @return
     */
    public abstract String act();
}
